<template>
  <div style="width:1000px; height: 500px; background-color: black;">
    <div :style="computedStyle" class="text-box" @mouseover="onMouseOver" @mouseout="onMouseOut">
      {{ text }}
      <div class="arrow" :style="arrowStyle"></div>
      <div class="circle" :style="circleStyle"></div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref } from 'vue';

const props = defineProps({
  text: String,
  top: Number,
  left: Number,
  scale: Number,
  opacity: Number,
  backgroundImage: String, // 新增背景图片属性
});

const isHovering = ref(false);

const computedStyle = computed(() => ({
  top: `${props.top}px`,
  left: `${props.left + 300}px`,
  transform: `scale(${props.scale})`,
  opacity: props.opacity,
  backgroundImage: `url(${props.backgroundImage})`, // 动态设置背景图片
  backgroundSize: 'cover', // 设置背景图片的大小
  backgroundPosition: 'center', // 居中显示背景图片
}));

const arrowStyle = computed(() => ({
  transform: `translateX(-50%) scale(${props.scale})`,
  opacity: props.opacity,
}));

const circleStyle = computed(() => ({
  transform: `translateX(-50%) scale(${props.scale})`,
  opacity: props.opacity,
}));

function onMouseOver() {
  isHovering.value = true;
  event.currentTarget.style.transform = 'translate(-50%, -50%) scale(1.5)';
}

function onMouseOut() {
  isHovering.value = false;
  event.currentTarget.style.transform = 'translate(-50%, -50%) scale(1.5)';
}
</script>

<style scoped>
.text-box {
  position: absolute;
  color: #FFA500;
  background-color: rgba(228, 170, 10, 0.7);
  /* 背景透明度 */
  padding: 15px 25px;
  /* 调整内边距 */
  border-radius: 5px;
  transition: all 0.3s ease;
  font-size: 24px;
  /* 字体大小 */
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.5);
  /* 阴影效果 */
  background-blend-mode: multiply;
  /* 混合背景图片与颜色 */
  transform-origin: center center;
  /* 确保缩放从中心开始 */
}

.text-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 165, 0, 0.5);
  /* 蒙层颜色（半透明黄色） */
  z-index: -1;
  /* 放置在图形的下层 */
  transition: background-color 0.3s ease;
  /* 添加平滑过渡效果 */
}

.text-box:hover {
  border-color: gray;
  /* 鼠标移入时边框颜色变为灰色 */
  transform: scale(1.1);
  /* 鼠标移入时放大 */
}

.text-box:hover::before {
  background-color: rgba(128, 128, 128, 0.3);
  /* 鼠标移入时蒙层颜色变为灰色 */
}

.arrow {
  position: absolute;
  bottom: -25px;
  /* 箭头距离词云底部的距离 */
  left: 50%;
  /* 居中 */
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 20px solid #FFA500;
  transition: border-color 0.3s ease;
}

.text-box:hover .arrow {
  border-top-color: gray;
  /* 鼠标移入时箭头颜色变为灰色 */
}

.circle {
  position: absolute;
  bottom: -30px;
  /* 圆形距离词云底部的距离 */
  left: 50%;
  /* 居中 */
  width: 40px;
  height: 10px;
  background-color: #FFA500;
  border-radius: 50%;
  /* 圆形 */
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.5);
  /* 阴影效果 */
  transition: background-color 0.3s ease;
}

.text-box:hover .circle {
  background-color: gray;
  /* 鼠标移入时圆形颜色变为灰色 */
  transform: scale(1.1);
  /* 鼠标移入时放大 */
}

.circle::before {
  content: "";
  position: absolute;
  bottom: -10px;
  /* 倒影距离圆形底部的距离 */
  left: 50%;
  /* 居中 */
  width: 80px;
  height: 10px;
  background-color: rgba(255, 165, 0, 0.5);
  border-radius: 50%;
  /* 圆形 */
  filter: blur(5px);
  /* 模糊效果 */
  opacity: 0.5;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}

.text-box:hover .circle::before {
  background-color: rgba(128, 128, 128, 0.5);
  /* 鼠标移入时倒影颜色变为灰色 */
  opacity: 0.5;
}
</style>